<%--
  Created by IntelliJ IDEA.
  User: 22541
  Date: 2022/4/7
  Time: 9:04
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>添加课程</title>
</head>
<body>
<div align="center">
<form action="CourseController?operation=add" name="add" method="post" onsubmit="return validateForm()">
    <h1>添加课程</h1>
    <table>
        <tr><td><span style="font-family: 'Microsoft YaHei UI' ; color: black; font-size: large">课程名称:</span>
        </td><td><input name="cName" size="22"></td></tr>
        <tr><td><span style="font-family: 'Microsoft YaHei UI' ; color: black; font-size: large">选课人数:</span>
        </td><td><input name="cNum" size="22"></td></tr>
        <tr><td>    <span style="font-family: 'Microsoft YaHei UI' ; color: black; font-size: large">课程类型：</span>
        </td><td><select id="cType" name="cType"><option value="0">选修</option>
            <option value="1">必修</option>
        </select>
        </td></tr>
    </table>

    <input type="submit" value="提交" >
</form>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</div>

<script>
    function validateForm()
    {
        let x = document.forms["add"]["cName"].value;
        let y = document.forms["add"]["cNum"].value;
        if (x == null || x === "")
        {
            alert("课程名不能为空！");
            return false;
        }else if(y == null || y === ""){
            alert("选课人数不得为空！")
            return false;
        }else if(y < 0){
            alert("选课人数应大于等于0！");
            return false;
        }
        return true;
    }
</script>

</body>
</html>
